class Observer {
    constructor(data){
        this.walk(data)
    }
    walk(data){
        //判断data是否为对象
        if(!data || typeof data !== 'object'){
            return
        }
        //遍历data的所有属性
        Object.keys(data).forEach(key =>{
            this.defineReactive(data, key ,data[key])
        })
    }
    defineReactive(obj, key ,value){
        this.walk[value]
        let that = this
        let dep = new Dep()
        Object.defineProperty(obj, key, {
            configurable: true,
            enumerable: true,
            get(){
                Dep.target && dep.subs.push(Dep.target)
                return value
            },
            set(nValue){
                if(nValue === value){
                    return
                }
                value = nValue
                //新赋值属性也要调用walk
                that.walk(value)
                //发送通知
                dep.notify()
            }
        })
    }
}